<?php 
	$SoQSDD = $_POST["SoQSDD"];
	$conn=mysql_connect("localhost","root","vertrigo") or die("Không thể kết nối!");
	mysql_select_db("webqtd")or die("không tồn tại CSDL\"webqtd\"!");
	mysql_query("SET NAMES 'utf8'"); //Để hiển thị unicode
	$sqlchecktrung = "SELECT * FROM taisanthechap WHERE SoQSDD ='$SoQSDD'";
	$rschecktrung = mysql_query($sqlchecktrung);
	if(mysql_num_rows($rschecktrung)>0)
	{
		$_SESSION["LoiThemTaiSanTheChap"] = "Đã trùng số quyền sử dụng đất";
		header("Location:index.php?do=themtaisanthechap");
		exit();
	}
	$SoHDTC = $_POST["SoHDTC"];
	$MaKH = $_POST["MaKH"];
	$NguoiThuaKe = $_POST["NguoiThuaKe"];
	$NgaySinh = $_POST["NgaySinh1"];
	$DiaChi = $_POST["DiaChi1"];
	$SoCMND = $_POST["SoCMND1"];
	$NgayCap = $_POST["NgayCap1"];
	$NoiCap = $_POST["NoiCap1"];
	$NoiCapDat = $_POST["NoiCapDat"];
	$NgayCapDat = $_POST["NgayCapDat"];
	$ThuaDatSo = $_POST["ThuaDatSo"];
	$MaDiaBan = $_POST["MaDiaBan"];
	$ToBanDoSo = $_POST["ToBanDoSo"];
	$TongDienTich = $_POST["DienTichDat"];
	$GiaTriTaiSan = $_POST["GiaTriTaiSan"];
	$MucChoVay = $_POST["MucChoVay"];
		
	$taisanthechap = new taisanthechapbs();
	$taisanthechap->SoHDTC = $SoHDTC;
	$taisanthechap->MaKH = $MaKH;
	$taisanthechap->NguoiThuaKe = $NguoiThuaKe;
	$taisanthechap->NgaySinh = $NgaySinh;
	$taisanthechap->DiaChi = $DiaChi;
	$taisanthechap->SoCMND = $SoCMND;
	$taisanthechap->NgayCap = $NgayCap;
	$taisanthechap->NoiCap = $NoiCap;
	$taisanthechap->SoQSDD = $SoQSDD;
	$taisanthechap->NoiCapDat = $NoiCapDat;
	$taisanthechap->NgayCapDat = $NgayCapDat;
	$taisanthechap->ThuaDatSo = $ThuaDatSo;
	$taisanthechap->MaDiaBan = $MaDiaBan;
	$taisanthechap->ToBanDoSo = $ToBanDoSo;
	$taisanthechap->TongDienTich= $TongDienTich;
	$taisanthechap->GiaTriTaiSan = $GiaTriTaiSan;
	$taisanthechap->MucChoVay = $MucChoVay;
	
	$kqtaisanthechap = $taisanthechap->Them();
	if($kqtaisanthechap)
	{
		$nhatky = new nhatkybs();
		$nhatky->TenSuKien = "Thêm tải sản thế chấp";
		$nhatky->MaNguoiDung = $_SESSION["MaND"];
		date_default_timezone_set('Asia/Ho_Chi_Minh');
		$nhatky->ThoiGian = date("Y-m-d H:m:s", time());
		$nhatky->Them();
		header("Location:index.php?do=laphopdongtindung&id=$SoHDTC");
	}
	else
	{
		header("Location:index.php?do=themtaisanthechap");
		$_SESSION["LoiThemTaiSanTheChap"] = "Lỗi: " . mysql_error();
	}
?>